<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单例模式</title>
</head>
<body>
     <script type="text/javascript">
         let single = function (name) {
             this.name = name
         }
         /**
          * 只实例化一个对象
          */
         let getSingle = (function () {
             let instance = null
             return function (name) {
                 if (!instance) {
                     instance = new single(name)
                 }
                 return instance
             }
         })()

         let person = getSingle("小明")
         console.log(person)
         let person2 = getSingle("小华")
         console.log(person2)
         console.log(person === person2)
     </script>
</body>
</html>